<template>
  <div class="report">
    <el-row style="margin:10px 0px">
      <el-col :span="6">
        <el-date-picker
          v-model="value2"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
        ></el-date-picker>
      </el-col>
      <el-col :span="1" style="margin-right:5px">
        <el-button type="primary">查询</el-button>
      </el-col>
      <el-col :span="3" style="margin-right:5px">
        <el-input placeholder="按商品编号查询">
          <el-button slot="append" icon="el-icon-search"></el-button>
        </el-input>
      </el-col>
      <el-col :span="3" style="margin-right:5px">
          <el-input placeholder="按商品名称查询">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
      </el-col>
      <el-col :span="1" style="margin-right:5px">
        <el-button type="primary">清空</el-button>
      </el-col>
    </el-row>
    <el-row>
      <el-table :data="noticeData" style="width: 100%" border>
        <el-table-column type="index" label="序号" width="200" align="center" :index="indexSort"></el-table-column>
        <el-table-column prop="createDate" label="更新时间" align="center"></el-table-column>
        <el-table-column prop="goods.goodsId" label="商品编号" align="center"></el-table-column>
        <el-table-column prop="goods.goodsName" label="商品名称" align="center"></el-table-column>
        <el-table-column prop="goods.goodsImg" label="商品图片" align="center">
          <template slot-scope="props">
            <img
              v-if="props.row.goods.goodsImg != null"
              :src="props.row.goods.goodsImg"
              alt
              width="70"
              height="70"
            />
          </template>
        </el-table-column>
        <el-table-column prop="price" label="价格" align="center"></el-table-column>
        <el-table-column prop="goodsNum" label="销量" align="center"></el-table-column>
      </el-table>
    </el-row>

    <el-row style="text-align: right;">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[15, 50, 100, 200]"
        :page-size="pageSize"
        layout="->, sizes, prev, pager, next, jumper, total"
        :total="totalElements"
      ></el-pagination>
    </el-row>
  </div>
</template>

<script>
import { getSingleSaleList } from "@/api/jxc/sale.js";
import * as util from "@/util/util.js";
export default {
  name: "volume",
  components: {},
  data() {
    return {
      value2: "",
      tabs: "areaSale",
      goodsNumber: "",
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      selectDate: "",
      noticeData: [],
      pageSize: 15,
      currentPage: 1,
      totalElements: 0,
      totalPages: 1,
      orderDialog: false,
      rowdata: {},
      title: ""
    };
  },
  created() {
    this.getList();
  },
  methods: {
    orderDetail(row) {
      console.log(row);
      this.rowdata = row;
      this.orderDialog = true;
    },
    add() {
      this.title = "新增仓库";
      this.supplierDialog = true;
    },
    del(row) {
      console.log("row", row);
      delWarehouse({ storehouseId: row.storehouseId }).then(
        res => {
          this.$notify.success("删除成功");
          this.getList();
        },
        err => {}
      );
    },
    getList() {
      getSingleSaleList({
        currentPage: this.currentPage,
        pageSize: this.pageSize
      }).then(
        res => {
          console.log("res单品销量接口", res);
          this.noticeData = res.data;
          this.noticeData.forEach(e => {
            e.createDate = util.timestampToTime(e.createDate);
          });
          this.totalElements = res.data.total;
        },
        err => {}
      );
    },
    //序号
    indexSort(index) {
      if (this.currentPage > 1) {
        index = (this.currentPage - 1) * this.pageSize + index + 1;
      } else {
        index = index + 1;
      }
      return index;
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getList();
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getList();
      console.log(`当前页: ${val}`);
    }
  }
};
</script>

<style lang="less" props>
.pushList {
}
</style>